package es.xpt.ysf.view;

import java.util.Locale;

import javax.faces.application.ViewHandler;
import javax.faces.application.ViewHandlerWrapper;
import javax.servlet.http.HttpSession;

import es.xpt.ysf.view.model.UserBean;
import es.xpt.ysf.web.Constants;

public class YSFViewHandler extends ViewHandlerWrapper {

private ViewHandler _parent;
	
	public YSFViewHandler(javax.faces.application.ViewHandler parent) {
		super();
		_parent = parent;
	}

	@Override
	public java.util.Locale calculateLocale(javax.faces.context.FacesContext context) {
		UserBean ub = (UserBean) ((HttpSession)context.getExternalContext().getSession(true)).getAttribute(Constants.USER_INFORMATION.getValue());
		Locale result = null;
		if (ub != null)
			result = ub.getLocale();
		
		if (result == null)
			result = context.getApplication().getDefaultLocale();
		
		return result;
	}

	@Override
	public ViewHandler getWrapped() {
		return _parent;
	}


}
